package com.liang.bishi.xm;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 2
 * 5
 * 1 3 5 2 4
 * 5 2 3 4 1
 * 7
 * 1 2 3 4 3 2 1
 * 4 3 2 1 2 3 4
 *
 * YES
 * NO
 */
public class Problem2 {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int T = cin.nextInt();
        while (T-- > 0) {
            int n = cin.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            for (int j = 0; j < n; j++) {
                a[j] = cin.nextInt();
            }
            for (int j = 0; j < n; j++) {
                b[j] = cin.nextInt();
            }
            System.out.println(getAnswer(n, a, b));
        }
    }

    public static String getAnswer(int n, int[] a, int[] b) {
        int[] aSorted = a.clone();
        int[] bSorted = b.clone();
        Arrays.sort(aSorted);
        Arrays.sort(bSorted);
        boolean aSortedFlag = isSortedArray(aSorted);
        boolean bSortedFlag = isSortedArray(bSorted);
        for (int i = 0; i < n; i++) {
            int temp = a[i];
            a[i] = b[i];
            b[i] = temp;

            if (isSortedArray(a)) {
                return "YES";
            }
            if (isSortedArray(b)) {
                return "YES";
            }

            a[i] = temp;
            b[i] = aSorted[i];
        }
        return (aSortedFlag || bSortedFlag) ? "YES" : "NO";
    }

    public static boolean isSortedArray(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                return false;
            }
        }
        return true;
    }

}
